package org.swingplus.core.engine;

import org.swingplus.core.annotation.Style;
import org.swingplus.core.annotation.layout.Layout;
import org.swingplus.core.annotation.widget.Widget;
import org.swingplus.core.bean.DefinitionMetadata;
import org.swingplus.core.bean.RootBeanDefinition;
import org.swingplus.core.factory.AbstractAutowireBeanFactory;
import org.swingplus.core.scanner.*;
import org.swingplus.core.utils.ClassFileInfoParseUtil;
import org.swingplus.core.utils.ObjectConvertUtil;
import org.swingplus.core.utils.StringUtil;

import java.util.List;
import java.util.Map;

public class ScannerEngine {

  private AbstractAutowireBeanFactory abstractAutowireBeanFactory=new AbstractAutowireBeanFactory();

    public void scan(Class<?> clazz){
        ApplicationScan.applicationScan(clazz);


//        BeanScan.scan();




        //目前传入clazz的不起作用
//        Map<Class,List<Object>> map=ComponentScan.scan("",clazz);

      //目前传入clazz的不起作用,
        Map<Class, Class[]> map=ComponentScan.scan("",clazz);
        
        List<Class> classList = AbstractAutowireBeanFactory.fieldsSingletonObjectsClass;
		for (Class class1 : classList) {
			DefinitionMetadata definitionMetadata = ClassFileInfoParseUtil.getDefinitionMetadata(class1);
			RootBeanDefinition rbd = ObjectConvertUtil.definitionMetadataToRootBeanDefinition(definitionMetadata);
			abstractAutowireBeanFactory.createBean(StringUtil.lowerFirst(class1.getSimpleName()), rbd);
		}
        
//        for (Class key : map.keySet()) {
//        	Class[] classes=map.get(key);
//        	
//        	for (Class class1 : classes) {
//
//        		 DefinitionMetadata  definitionMetadata = ClassFileInfoParseUtil.getDefinitionMetadata(class1);
//        		 RootBeanDefinition rbd = ObjectConvertUtil.definitionMetadataToRootBeanDefinition(definitionMetadata);
//        		 abstractAutowireBeanFactory.createBean(class1.getSimpleName(),rbd);  
//			}
//        	 
//		}
        
//        
       
        
//        FieldAutowiredFactory.
        
        

//        List<Object> widgetList=map.get(Widget.class);

        //TODO 现在只扫描了widget
//        BeanScan.scan(widgetList);

        //初始化Autowired的注入
//        AutowiredScan.scan(map);

        //初始化类上的属性
//        WidgetScan.widgetScan(widgetList);


//        StyleScan.styleScan("",Style.class);
//        LayoutScan.layoutScan("",Layout.class);
//        WidgetScan.widgetScan(clazz);

//        WidgetScan.widgetScan(clazz);

        //部件的监听事件
//        ListenerScan.listenerScan(widgetList);

        //当前类的执行方法栈
        //TODO 变量的未实现
        try {
//            OrderScan.orderScan(widgetList);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }


}
